package cn.com.zonesion.rfiddemo.fragment.icfragment;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.com.zonesion.rfiddemo.R;
import cn.com.zonesion.rfiddemo.base.BaseFragment;

/**
 * Created by Administrator on 2018/4/24.
 */

public class IcBasicsFragment extends BaseFragment {
    @BindView(R.id.spacer_a_sector)
    Spinner ttySpinnerSector;
    @BindView(R.id.spacer_a_sector_faster_system)
    Spinner ttySpinnerSectorFasterSystem;
    @BindView(R.id.spacer_block_number)
    Spinner ttySpinnerBlockNumber;
    @BindView(R.id.radio_group_type_pattern)
    RadioGroup radioGroup;
    @BindView(R.id.rb_pattern_a)
    RadioButton rbPatternA;
    @BindView(R.id.rb_pattern_b)
    RadioButton rbPatternB;
    
    /**
     * 扇区数组，用来存放常用数组
     */
    private String[] aSectorArray;
    /**
     * 块编号数组，用来存放常用数组
     */
    private String[] blockNumberArray;
    /**
     * 对应的扇区
     */
    private int baudrate;
    /**
     * 系统块读写对应的扇区
     */
    private int fasterSystemSector;
    /**
     * 块编号
     */
    private int blockNumber;
    /**
     * Unbinder对象，用来解除ButterKnife与Fragment对象的绑定
     */
    private Unbinder unbinder;
    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.basics_ic_item, null);
        unbinder = ButterKnife.bind(this, view);//将ButterKnife与ICBasicsFragment进行绑定，并返回一个Unbinder对象
        return view;
    }

    @Override
    public void initData() {
        super.initData();
        init();
    }
    private void init(){
        rbPatternA.setChecked(true);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId == rbPatternA.getId()) {
                    
                }else if(checkedId == rbPatternB.getId()) {
                    
                }
            }
        });
       aSectorArray = getResources().getStringArray(R.array.a_sector);
       blockNumberArray = getResources().getStringArray(R.array.block_number);
        ttySpinnerSector.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,aSectorArray));
        ttySpinnerSectorFasterSystem.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,aSectorArray));
        ttySpinnerBlockNumber.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,blockNumberArray));
        //ttySpinnerSector设置适配器（修改密码扇区）
        ttySpinnerSector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                baudrate = Integer.parseInt(aSectorArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {}
        });
        //ttySpinnerSectorFasterSystem设置适配器（系统块读写扇区）
        ttySpinnerSectorFasterSystem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                fasterSystemSector = Integer.parseInt(aSectorArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {}
        });
        //ttySpinnerBlockNumber设置适配器（块编号）
        ttySpinnerBlockNumber.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                blockNumber = Integer.parseInt(blockNumberArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {}
        });

    }
    @Override
    public void onDestroy() {
        //解除ButterKnife与ICBasicsFragment的绑定
       unbinder.unbind();
        super.onDestroy();
    }
    @OnClick({R.id.btn_modify_the_password,R.id.btn_scavenging,R.id.btn_start_looking_for_a_card,R.id.btn_read_scavenging,R.id.btn_read,R.id.btn_write_in})
    public void onClick(View view) {
        switch (view.getId()) {
            case  R.id.btn_modify_the_password://修改密码

                break;
            case  R.id.btn_scavenging://寻卡操作：清除

                break;
            case  R.id.btn_start_looking_for_a_card://寻卡操作：开始寻卡

                break;
            case  R.id.btn_read_scavenging://清除

                break;
            case  R.id.btn_read://读取

                break;
            case  R.id.btn_write_in://写入

                break;
        }
    }
}
